package monster

import (
	"idle/internal/game/attr"
	"idle/internal/game/enum"
	"idle/internal/game/skill"
)

type Monster struct {
	//fight.IFighter
	Cid       int
	Name      string
	Lv        int
	Exp       int
	Hp        int
	attrMap   map[attr.Attribute]int //属性
	SkillList []skill.Skill
}

func (m *Monster) SetAttr(attr attr.Attribute, value int) {
	m.attrMap[attr] = value
}

func NewMonster() *Monster {
	return &Monster{
		Cid:       0,
		Lv:        0,
		Exp:       0,
		attrMap:   make(map[attr.Attribute]int),
		SkillList: make([]skill.Skill, 0),
	}
}

func (m *Monster) GetAttr(attr attr.Attribute) int {
	if val, ok := m.attrMap[attr]; ok {
		return val
	}
	m.attrMap[attr] = 0
	return 0
}

func (m *Monster) GetActionSpeedGear() int {
	attackSkillNum := 0
	spellSkillsNum := 0
	for _, s := range m.SkillList {
		if s.Typ == enum.AttackSkill {
			attackSkillNum += 1
		} else if s.Typ == enum.SpellSkills {
			spellSkillsNum += 1
		}
	}
	if spellSkillsNum > attackSkillNum {
		return m.GetAttr(attr.CastSpeedGear)
	} else {
		return m.GetAttr(attr.AttackSpeedGear)
	}
}

func (m *Monster) GetName() string {
	return m.Name
}
func (m *Monster) GetHp() int {
	return m.Hp
}
func (m *Monster) GetLv() int {
	return m.Lv
}
